package org.example.sping_aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Slf4j
@Component
public class TimeRecordAspect {
    @Around("execution(* org.example.sping_aop.controller.*.*(..))")
    public Object timeRecord(ProceedingJoinPoint pjt) {
        log.info("TimeRecordAspect前...");
        long start = System.currentTimeMillis();  //开始的时间

//    执行方法
        Object o = null;
        try {
             o = pjt.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }

        long end = System.currentTimeMillis(); //结束的时间
        log.info("TimeRecordAspect后...");
        log.info(pjt.getSignature()+"耗时: "+ (end - start) + "ms");
        return o;
    }
}
